<template>
  <div>
    <p>订单类型饼状图</p>
    <div id="ordertype" :style="{width: '100%', height: '300px'}" />
  </div>
</template>
<script>
import Vue from 'vue'
import echarts from 'echarts'
Vue.prototype.$echarts = echarts
export default {
  name: 'Hello',
  props: ["message4"],
  data() {
    return {
      msg: 'Welcome to Your Vue.js App'
    }
  },
  watch: {
    message4: function(newVal, oldVal) {
      let ptarr = newVal[0].total;
      let bjarr = newVal[1].total;
      this.drawLine(ptarr,bjarr);
    }
  },
  methods: {
    drawLine(p,b) {
      // 基于准备好的dom，初始化echarts实例
      const myChart = this.$echarts.init(document.getElementById('ordertype'))
      // 绘制图表
      myChart.setOption({
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b}: {c} ({d}%)'
        },
        legend: {
          orient: 'vertical',
          x: 'left',
          data: ['普通单', '报价单']
        },
        series: [
          {
            name: '访问来源',
            type: 'pie',
            radius: ['50%', '70%'],
            avoidLabelOverlap: false,
            label: {
              normal: {
                show: false,
                position: 'center'
              },
              emphasis: {
                show: true,
                textStyle: {
                  fontSize: '30',
                  fontWeight: 'bold'
                }
              }
            },
            labelLine: {
              normal: {
                show: false
              }
            },
            data: [
              { value: p, name: '普通单' },
              { value: b, name: '报价单' }
            ]
          }
        ]
      })
    }
  }
}
</script>
